Skip to content

Add Kotlin code examples to last writing tests topics - #5898

Open
danil-pavlov wants to merge 7 commits into
junit-team:mainfrom
danil-pavlov:writing-tests-kotlin-part5
Open

Add Kotlin code examples to last writing tests topics#5898
danil-pavlov wants to merge 7 commits into
junit-team:mainfrom
danil-pavlov:writing-tests-kotlin-part5

Conversation

@danil-pavlov

Copy link
Copy Markdown
Contributor

Adds Kotlin tabbed code snippets to the last three topics in the Writing Tests section of the User Guide,
continuing the effort in #5853

Pages updated:

  • Tagging and Filtering
  • Test Execution Order
  • Parameterized Classes and Tests

I hereby agree to the terms of the JUnit Contributor License Agreement.


Definition of Done

@danil-pavlov
danil-pavlov force-pushed the writing-tests-kotlin-part5 branch 2 times, most recently from 044fbcd to e7be7e3 Compare July 22, 2026 11:07
Comment thread documentation/src/test/kotlin/example/kotlin/ParameterizedClassDemo.kt Outdated
@danil-pavlov
danil-pavlov requested a review from marcphilipp July 27, 2026 12:39
Comment thread documentation/src/test/kotlin/example/kotlin/ParameterizedTestDemo.kt Outdated
Comment thread documentation/src/test/kotlin/example/kotlin/ParameterizedTestDemo.kt Outdated
}

// tag::parameter_resolution_factory_MethodSource_example[]
fun factoryMethodWithArguments(quantity: Int): Stream<Arguments> =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method isn't found like this, is it? Please run ./gradlew consoleLauncherTest to execute these new snippets.

@danil-pavlov danil-pavlov Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I indeed missed these errors cause the weren't discoverable by our other test tasks. To fix the failing consoleLauncherTest, I went with the PER_CLASS approach, which also helped clean up extra tags and includes. But if you don't agree, I can try some other workaround

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's ok but we should add a note in the Kotlin tabs, below the code block, of all such snippets:

NOTE: For conciseness, this snippet assumes that the enclosing test classes used the `PER_CLASS` xref:writing-tests/test-instance-lifecycle.adoc[].

@danil-pavlov
danil-pavlov requested a review from marcphilipp July 30, 2026 15:04

@marcphilipp marcphilipp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there!

Comment on lines +415 to +417
class Book(
val title: String
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing a @JvmStatic fromTitle() method.

@danil-pavlov danil-pavlov Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I was trying to avoid companion objects, but now that we use PER_CLASS for other examples in this file, I think it's OK to use it for just this one

* https://www.eclipse.org/legal/epl-v20.html
*/

package example.kotlin

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should include the package declaration in the rendered snippet because it's referenced below. If that doesn't work due to the formatter, we can duplicate it in the adoc file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I had it originally (24490a6), I guess it's the formatter problem

@danil-pavlov
danil-pavlov requested a review from marcphilipp July 31, 2026 18:18
@danil-pavlov
danil-pavlov force-pushed the writing-tests-kotlin-part5 branch from 1ce793d to f998178 Compare July 31, 2026 18:27
danil-pavlov and others added 7 commits July 31, 2026 20:41
Signed-off-by: Danil Pavlov <danil.pavlov@jetbrains.com>
Signed-off-by: Danil Pavlov <danil.pavlov@jetbrains.com>
Signed-off-by: Danil Pavlov <danil.pavlov@jetbrains.com>
Signed-off-by: Danil Pavlov <danil.pavlov@jetbrains.com>
Signed-off-by: Danil Pavlov <danil.pavlov@jetbrains.com>
Signed-off-by: Danil Pavlov <danil.pavlov@jetbrains.com>
Signed-off-by: Danil Pavlov <danil.pavlov@jetbrains.com>
@danil-pavlov
danil-pavlov force-pushed the writing-tests-kotlin-part5 branch from f998178 to 0c2db3e Compare July 31, 2026 18:44
@testlens-app

testlens-app Bot commented Jul 31, 2026

Copy link
Copy Markdown

🚨 TestLens detected 4 failed tests 🚨

Here is what you can do:

  1. Inspect the test failures carefully.
  2. If you are convinced that some of the tests are flaky, you can mute them below.
  3. Finally, trigger a rerun by checking the rerun checkbox.

Test Summary

CI / Build / Windows > :junit-vintage-engine:test_4_12

Test Runs Flakiness
ParallelExecutionIntegrationTests > executesTestClassesAndMethodsInParallel(TestReporter) 7% 🟠

CI / Cross-Version / OpenJDK 26 (ga) > :junit-vintage-engine:test_4_12

Test Runs Flakiness
ParallelExecutionIntegrationTests > executesTestClassesAndMethodsInParallel(TestReporter) 7% 🟠

CI / Cross-Version / OpenJDK 26 (leyden) > :junit-vintage-engine:test_4_12

Test Runs Flakiness
ParallelExecutionIntegrationTests > executesTestClassesAndMethodsInParallel(TestReporter) 7% 🟠

CI / Cross-Version / OpenJDK 27 (ea) > :junit-vintage-engine:test_4_12

Test Runs Flakiness
ParallelExecutionIntegrationTests > executesTestClassesAndMethodsInParallel(TestReporter) 7% 🟠

CI / Cross-Version / OpenJDK 28 (ea) > :junit-vintage-engine:test_4_12

Test Runs Flakiness
ParallelExecutionIntegrationTests > executesTestClassesAndMethodsInParallel(TestReporter) ⚠️ 7% 🟠

🏷️ Commit: 0c2db3e
▶️ Tests: 941 executed
⚪️ Checks: 17/17 completed

Test Failures (first 10 of 14)

ParallelExecutionIntegrationTests > executesTestClassesAndMethodsInParallel(TestReporter) (:junit-vintage-engine:test\_4\_12 in CI / Build / Windows)
java.lang.AssertionError: 
Expected size: 3 but was: 4 in:
["ForkJoinPool-1-worker-1",
    "ForkJoinPool-1-worker-4",
    "ForkJoinPool-1-worker-2",
    "ForkJoinPool-1-worker-3"]
	at org.junit.vintage.engine.execution.ParallelExecutionIntegrationTests.executesTestClassesAndMethodsInParallel(ParallelExecutionIntegrationTests.java:135)
ParallelExecutionIntegrationTests > executesTestClassesAndMethodsInParallel(TestReporter) (:junit-vintage-engine:test\_4\_12 in CI / Build / Windows)
java.lang.AssertionError: 
Expected size: 3 but was: 4 in:
["ForkJoinPool-5-worker-2",
    "ForkJoinPool-5-worker-3",
    "ForkJoinPool-5-worker-4",
    "ForkJoinPool-5-worker-1"]
	at org.junit.vintage.engine.execution.ParallelExecutionIntegrationTests.executesTestClassesAndMethodsInParallel(ParallelExecutionIntegrationTests.java:135)
ParallelExecutionIntegrationTests > executesTestClassesAndMethodsInParallel(TestReporter) (:junit-vintage-engine:test\_4\_12 in CI / Build / Windows)
java.lang.AssertionError: 
Expected size: 3 but was: 4 in:
["ForkJoinPool-6-worker-2",
    "ForkJoinPool-6-worker-1",
    "ForkJoinPool-6-worker-4",
    "ForkJoinPool-6-worker-3"]
	at org.junit.vintage.engine.execution.ParallelExecutionIntegrationTests.executesTestClassesAndMethodsInParallel(ParallelExecutionIntegrationTests.java:135)
ParallelExecutionIntegrationTests > executesTestClassesAndMethodsInParallel(TestReporter) (:junit-vintage-engine:test\_4\_12 in CI / Cross-Version / OpenJDK 26 (ga))
java.lang.AssertionError: 
Expected size: 3 but was: 4 in:
["ForkJoinPool-1-worker-1",
    "ForkJoinPool-1-worker-4",
    "ForkJoinPool-1-worker-2",
    "ForkJoinPool-1-worker-3"]
	at org.junit.vintage.engine.execution.ParallelExecutionIntegrationTests.executesTestClassesAndMethodsInParallel(ParallelExecutionIntegrationTests.java:135)
ParallelExecutionIntegrationTests > executesTestClassesAndMethodsInParallel(TestReporter) (:junit-vintage-engine:test\_4\_12 in CI / Cross-Version / OpenJDK 26 (ga))
java.lang.AssertionError: 
Expected size: 3 but was: 4 in:
["ForkJoinPool-5-worker-2",
    "ForkJoinPool-5-worker-3",
    "ForkJoinPool-5-worker-4",
    "ForkJoinPool-5-worker-1"]
	at org.junit.vintage.engine.execution.ParallelExecutionIntegrationTests.executesTestClassesAndMethodsInParallel(ParallelExecutionIntegrationTests.java:135)
ParallelExecutionIntegrationTests > executesTestClassesAndMethodsInParallel(TestReporter) (:junit-vintage-engine:test\_4\_12 in CI / Cross-Version / OpenJDK 26 (ga))
java.lang.AssertionError: 
Expected size: 3 but was: 4 in:
["ForkJoinPool-6-worker-2",
    "ForkJoinPool-6-worker-1",
    "ForkJoinPool-6-worker-4",
    "ForkJoinPool-6-worker-3"]
	at org.junit.vintage.engine.execution.ParallelExecutionIntegrationTests.executesTestClassesAndMethodsInParallel(ParallelExecutionIntegrationTests.java:135)
ParallelExecutionIntegrationTests > executesTestClassesAndMethodsInParallel(TestReporter) (:junit-vintage-engine:test\_4\_12 in CI / Cross-Version / OpenJDK 26 (leyden))
java.lang.AssertionError: 
Expected size: 3 but was: 4 in:
["ForkJoinPool-1-worker-1",
    "ForkJoinPool-1-worker-4",
    "ForkJoinPool-1-worker-2",
    "ForkJoinPool-1-worker-3"]
	at org.junit.vintage.engine.execution.ParallelExecutionIntegrationTests.executesTestClassesAndMethodsInParallel(ParallelExecutionIntegrationTests.java:135)
ParallelExecutionIntegrationTests > executesTestClassesAndMethodsInParallel(TestReporter) (:junit-vintage-engine:test\_4\_12 in CI / Cross-Version / OpenJDK 26 (leyden))
java.lang.AssertionError: 
Expected size: 3 but was: 5 in:
["ForkJoinPool-5-worker-2",
    "ForkJoinPool-5-worker-3",
    "ForkJoinPool-5-worker-4",
    "ForkJoinPool-5-worker-5",
    "ForkJoinPool-5-worker-1"]
	at org.junit.vintage.engine.execution.ParallelExecutionIntegrationTests.executesTestClassesAndMethodsInParallel(ParallelExecutionIntegrationTests.java:135)
ParallelExecutionIntegrationTests > executesTestClassesAndMethodsInParallel(TestReporter) (:junit-vintage-engine:test\_4\_12 in CI / Cross-Version / OpenJDK 26 (leyden))
java.lang.AssertionError: 
Expected size: 3 but was: 5 in:
["ForkJoinPool-6-worker-2",
    "ForkJoinPool-6-worker-1",
    "ForkJoinPool-6-worker-4",
    "ForkJoinPool-6-worker-3",
    "ForkJoinPool-6-worker-5"]
	at org.junit.vintage.engine.execution.ParallelExecutionIntegrationTests.executesTestClassesAndMethodsInParallel(ParallelExecutionIntegrationTests.java:135)
ParallelExecutionIntegrationTests > executesTestClassesAndMethodsInParallel(TestReporter) (:junit-vintage-engine:test\_4\_12 in CI / Cross-Version / OpenJDK 27 (ea))
java.lang.AssertionError: 
Expected size: 3 but was: 5 in:
["ForkJoinPool-1-worker-6",
    "ForkJoinPool-1-worker-1",
    "ForkJoinPool-1-worker-4",
    "ForkJoinPool-1-worker-5",
    "ForkJoinPool-1-worker-3"]
	at org.junit.vintage.engine.execution.ParallelExecutionIntegrationTests.executesTestClassesAndMethodsInParallel(ParallelExecutionIntegrationTests.java:135)

Muted Tests

Select tests to mute in this pull request:

  • ParallelExecutionIntegrationTests > executesTestClassesAndMethodsInParallel(TestReporter)

Reuse successful test results:

  • ♻️ Only rerun the tests that failed or were muted before

Click the checkbox to trigger a rerun:

  • Rerun jobs

Learn more about TestLens at testlens.app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants